<?php declare(strict_types=1);


namespace PinWuYun\domain\dao;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use PinWuYun\domain\models\OrderRelationModel;

/**
 * Created: by zhiJie
 * Date: 2021/7/3
 */
class OrderRelationDao
{
    public function insert(array $params): bool
    {
        $model = new OrderRelationModel();
        $model->setRawAttributes([
            'item_id' => $params['item_id'],
            'you_sku_id' => $params['you_sku_id'],
            'code' => $params['code'],
        ]);
        return $model->save();
    }

    /**
     * 通过星链子订单号获取关联的有赞订单信息
     * @param $orderSn
     * @return Builder|Model|object|null
     */
    public function getOneByOrderSn($orderSn)
    {
        return OrderRelationModel::query()->where(['star_order_sn' => $orderSn])->first();
    }
}